<template>
<view>
  <!-- 拼团列表 -->
  <view v-for="(item, index) in shopList" :key="index" class="tuanList">
    <image :src="item.thumb_img"></image>
    <view>
      <view class="tuanListTitle">{{item.goods_name}}</view>
      <view class="tuanListNum">
        <view class="oldMoney">￥{{item.price}}</view>
        <view class="sellNum">已售<text style="color:#E51F54">{{item.sold}}</text>件</view>
      </view>
      <view class="tuanListMessage">
        <view class="tuanListMessage-left">
          {{item.group_need_num}}人团<text style="color:#E51F54">{{item.group_price}}</text>元
        </view>
        <view class="tuanListMessage-right" :data-index="index" @tap="toGroupDetails">
          立即拼团
        </view>
      </view>
    </view>
  </view>
  <!-- 拼团列表End -->
</view>
</template>

<script>
import api from "../../../api";
var app = getApp();

export default {
  data() {
    return {
      userId: '',
      // 商品列表
      shopList: []
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    // 获取请求Unicodeid
    this.getlist();
  },
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    //加载数据
    getlist() {
      let that = this;
      app.globalData.request({
        url: api.fyz.indexToday,
        data: {
          goods_type: 2
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值

        },
        method: 'POST',
        success: res => {
          console.log(res);
          that.setData({
            shopList: res.list
          });
        },
        fail: function (res) {//失败后的逻辑
        }
      });
    },

    // 拼团商品详情
    toGroupDetails(e) {
      let index = e.currentTarget.dataset.index;
      console.log(e.currentTarget.dataset.index);
      wx.navigateTo({
        url: '../groupdetails/groupdetails?goods_id=' + this.shopList[index].goods_id + ''
      });
    }

  }
};
</script>
<style>
@import "./groupbook.css";
</style>